package com.jiangxjsy.model.crm.bo;

import cn.hutool.core.util.StrUtil;
import com.jiangxjsy.core.constant.BasicConstant;
import com.jiangxjsy.core.enums.FieldEnum;
import com.jiangxjsy.model.crm.entity.CrmField;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * wukong-crm-master
 * 蒋胜宇
 * 2025/6/19 15:06
 */

@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CrmFieldBO extends CrmField implements Serializable {
    private String formType;
    private List<String> setting;
    private Integer xAxis;
    private Integer yAxis;
    private Map<String, Object> optionsData;
    private List<CrmFieldExtendBO> fieldExtendList;

    public CrmFieldBO(String fieldName, String name, FieldEnum fieldEnum) {
        super.setFieldName(fieldName);
        super.setName(name);
        super.setType(Long.valueOf(fieldEnum.getType()));
    }

    public void setFormPosition(String formPosition) {
        super.setFormPosition(formPosition);
        if (StrUtil.isNotEmpty(formPosition)){
            if (formPosition.contains(BasicConstant.SEPARATOR)){
                String[] axisArr = formPosition.split(BasicConstant.SEPARATOR);
                if (axisArr.length == 2){
                    if (axisArr[0].matches("[0-9]+") && axisArr[1].matches("[0-9]+")) {
                        this.xAxis = Integer.valueOf(axisArr[0]);
                        this.yAxis = Integer.valueOf(axisArr[1]);
                        return;
                    }
                }
            }
        }
        this.xAxis = -1;
        this.yAxis = -1;
    }
}
